import QtQuick 1.0

// Form for creating new items
Rectangle {
    id: addBlock
    width: 250
    height: 60
    color: "#50000000"
    border.color: "orange"

    property int rowCount: 3
    property int key: 0
    property alias value: valueEdit.text

    signal commit()

    onCommit:
    {
        if ( keyEdit.text.length > 0 )
            key = keyEdit.text
        keyEdit.text = ""
        keyEdit.focus = true
    }

    property SystemPalette palette

    Column {
        id: addColumn
        spacing: 2
        anchors.fill: addBlock
        anchors.margins: 5

        Row {
            id: keyRow
            spacing: 1
            height: addColumn.height / rowCount
            width: addColumn.width

            Text {
                id: keyLabel
                text: "Key:"
                color: palette.light
                width: keyRow.width * 0.18
            }

            Rectangle {
                width: keyEdit.width
                height: keyEdit.height
                border.width: 1
                border.color: keyEdit.focus ? palette.light : Qt.darker(palette.light)
                color: palette.dark

                TextInput {
                    id: keyEdit
                    width: Math.floor(keyRow.width * 0.8)
                    height: keyRow.height - 2
                    validator: IntValidator { bottom: 1; }
                    focus: true
                    anchors.margins: 2
                }
            }
        }

        Row {
            id: valueRow
            spacing: 1
            height: addColumn.height / rowCount
            width: addColumn.width

            Text {
                id: valueLabel
                text: "Value:"
                color: palette.light
                width: valueRow.width * 0.18
            }

            Rectangle {
                width: valueEdit.width
                height: valueEdit.height
                border.width: 1
                border.color: valueEdit.focus ? palette.light : Qt.darker(palette.light)
                color: palette.dark

                TextInput {
                    id: valueEdit
                    width:  Math.floor(valueRow.width * 0.8)
                    height: valueRow.height - 2
                    anchors.margins: 2
                }
            }
        }

        Button {
            id: add
            onClicked: commit();
            height: addColumn.height / rowCount
            width: addColumn.width - 4
            anchors.horizontalCenter: parent.horizontalCenter
            buttonText: "Добавить"
            radius: 5
        }
    }
}
